<?php
include('../includes/definer.php');
include(INC.'php/bootstrap.php');

$fechas = array();
$currentDay = date('d-m-Y', strtotime('-14 day'));

for ($i=0; $i<14; $i++) {
    $default[] = 0;
    $currentDay= date('d-m-Y', strtotime('+1 day', strtotime($currentDay))) ;
    $fechas[] = $currentDay;
    
}



$visitas = Doctrine_Query::create()
        ->select('count(v.fecha) as total, DATE_FORMAT(v.fecha, "%d-%m-%Y") as dia')
        ->from('Visita v')
        //->where('v.fecha > DATE_SUB(NOW(), INTERVAL 30 DAY)')
        ->whereIn('DATE_FORMAT(v.fecha, "%d-%m-%Y")', $fechas)
        ->groupBy('dia')
        ->execute(array(), Doctrine::HYDRATE_ARRAY)
;


$dias = array();
$totales = array();
foreach ($visitas as $visita) {
    $dias[] = $visita['dia'];
    $totales[] = $visita['total'];
}
$result = array('dias'=>$dias, 'totales'=>$totales);
header("Content-type: application/json");
echo(json_encode($result, JSON_NUMERIC_CHECK));exit();
?>
